Maps discrete variables to six easily discernible shapes and then convert them with ggplotly.
dsmall <- diamonds[sample(nrow(diamonds), 100), ]
(d <- ggplot(dsmall, aes(carat, price)) + geom_point(aes(shape = cut)))
plotly::ggplotly(d)
## Warning: Using shapes for an ordinal variable is not advised
dsmall <- diamonds[sample(nrow(diamonds), 100), ]
(d <- ggplot(dsmall, aes(carat, price)) + geom_point(aes(shape = cut)))
p <- d + scale_shape(solid = TRUE) # the default
plotly::ggplotly(p)
dsmall <- diamonds[sample(nrow(diamonds), 100), ]
(d <- ggplot(dsmall, aes(carat, price)) + geom_point(aes(shape = cut)))
p <- d + scale_shape(solid = FALSE)
plotly::ggplotly(p)
dsmall <- diamonds[sample(nrow(diamonds), 100), ]
(d <- ggplot(dsmall, aes(carat, price)) + geom_point(aes(shape = cut)))
p <- d + scale_shape(name = "Cut of diamond")
plotly::ggplotly(p)
dsmall <- diamonds[sample(nrow(diamonds), 100), ]
(d <- ggplot(dsmall, aes(carat, price)) + geom_point(aes(shape = cut)))
levels(dsmall$cut) <- c("Fair", "Good", "Very Good", "Premium", "Ideal")
p <- ggplot(dsmall, aes(price, carat)) + geom_point(aes(shape = cut))
plotly::ggplotly(p)
## Warning: Using shapes for an ordinal variable is not advised
df_shapes <- data.frame(shape = 0:24)
p <-
ggplot(df_shapes, aes(0, 0, shape = shape)) +
geom_point(aes(shape = shape), size = 5, fill = 'red') +
scale_shape_identity() +
facet_wrap(~shape) +
theme_void()
plotly::ggplotly(p)